package com.mxl.dao.channel.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.util.Assert;

import com.mxl.dao.channel.ChannelGatewayRelationDao;
import com.mxl.dao.channel.model.ChannelGatewayRelation;
import com.mxl.datebase.orm.hibernate.BaseDaoSupport;

/**
 * 所以的渠道都采取19pay-mobile模式 前面是渠道名-后面是卡类型 错误吗是根据一个渠道来的 所以一个渠道就只有一套错误吗 所以请求传过来的code
 * 为19pay-mobile 需要解析最后传入 数据库查询的code 为19pay
 * 
 * @author xianglin.mo
 * 
 */
public class ChannelGatewayRelationDaoImpl extends
		BaseDaoSupport<ChannelGatewayRelation, Long> implements
		ChannelGatewayRelationDao {

	public ChannelGatewayRelation getGatewayCodeByChannelAndCode(String code,
			int status, String errorCode) {
		Assert.notNull(code,
				"query ChannelGatewayRelation code must be not null");
		// 处理渠道
		String[] codes = code.split("-");
		List<Criterion> criterions = new ArrayList<Criterion>();
		criterions.add(Restrictions.eq("channelCode", codes[0]));
		if (status > 0) {
			criterions.add(Restrictions.eq("status", status));
		}
		criterions.add(Restrictions.eq("channelRespCode", errorCode));
		return super.findUnique(criterions.toArray(new Criterion[criterions
				.size()]));
	}

}
